<!Doctype html>
<html xmlns:th="http://www.thymeleaf.org" lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <script th:src="@{/jquery-1.11.3.min.js}"></script>
    <link th:href="@{/bootstrap-4.5.0-dist/css/bootstrap.css}" rel="stylesheet">
<!--    <script th:src="@{/jquery/jqPaginator.js}"></script>-->
</head>

<body>
    <div class="container">
        <h3 class="text-center">房源列表</h3><br>
        <div style="margin-top: 25px;margin-bottom: 10px">
            <a class="btn btn-success" th:href="@{/restful/house}">添加</a>
            <br>
            <input type="text" class="am-form-field" style="margin-bottom: 20px;width: 250px;height: 40px" placeholder="请输入地点查询" id="houseadress">
            <span class="am-input-group-btn">
                            <button class="btn btn-success" onclick="showHouse()"><span>搜索</span></button>
                            <button class="btn btn-danger" ><a>返回</a></button>
                </span>
        </div>


<!--        <div class="am-input-group am-input-group-sm" style="float: right;margin-top: 20px">-->
<!--            -->
<!--        </div>-->

        <table class="table">
    <tr><th>房屋编号</th><th>房屋名称</th><th>房屋地址</th><th>房屋面积(㎡)</th><th>房屋类型</th><th>房屋价格(万)</th><th>房屋状态</th><th>用户编号</th><th>图片</th><th>操作</th></tr>

    <tr th:each="one:${houses}">
        <td th:text="${one.house_id}"></td>
        <td th:text="${one.housename}"></td>
        <td th:text="${one.houseaddress}"></td>
        <td th:text="${one.housesize}"></td>
        <td th:text="${one.housetype}"></td>
        <td th:text="${one.houseprice}"></td>
        <td th:text="${one.housestate}"></td>
        <td th:text="${one.user_id}"></td>
        <td><img th:src="@{${one.jpg}}" src=""></td>
        <td> <a class="btn btn-primary" th:href="@{/restful/house/} + ${one.house_id}">修改</a>
            <a class="btn btn-danger" href="javascript:void(0)" th:onclick="|del(${one.house_id})|">删除</a>
        </td>
    </tr>


    <tr>
        <td colspan="8">
            <div class="pagelist">
                <p>当前<span th:text="${houses.getNumber()} + 1"></span>页,总<span th:text="${houses.totalPages}"></span>页
                    共<span th:text="${houses.totalElements}"></span>条记录
                    <a th:href="@{/restful/house1}">首页</a>
                    <a th:href="@{/restful/house1(pageNum = ${houses.hasPrevious()} ? ${houses.getNumber() } : 1)}">上一页</a>
                    <a th:href="@{/restful/house1(pageNum = ${houses.hasNext()} ? ${houses.getNumber()} + 2 : ${houses.totalPages})}">下一页</a>
                    <a th:href="@{/restful/house1(pageNum = ${houses.totalPages})}">尾页</a></p>
            </div>

        </td>
    </tr>
</table>

</div>


<!--       <script>
           function showHouse() {
               var houseadress = $("#houseadress").val();
               $.ajax({
                   url:"/restful/housefind",
                   data:{"houseaddress":houseaddress},
                   success:function(data){

                   },
               });
           }


       </script>-->

<script th:inline="javascript">
    function del(id) {
        if(confirm("确定要删除?")){

            $.ajax({
                url:[[@{/restful/house/}]] +id, method:"POST",
                data:{
                _method:"delete"
            },
            success:function(data) {
                if(data=="ok"){
                    alert("删除成功")
                    location.reload();
                }
                else {
                    alert("删除失败");
                }
            }
        });
        }
    }
</script>
</body>
</html>